<!--********************************************************************
* Copyright© 2000 - 2025 SuperMap Software Co.Ltd. All rights reserved.
*********************************************************************-->
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title data-i18n="resources.title_cartoCSSPoint"></title>
    <style type="text/css">
        body {
            margin: 0;
            overflow: hidden;
            background: #fff;
            width: 100%;
            height: 100%
        }

        #map {
            position: absolute;
            width: 100%;
            height: 100%;
        }

        #toolbar {
            position: absolute;
            top: 50px;
            right: 10px;
            text-align: center;
            z-index: 100;
            border-radius: 4px;
        }

        img {
            margin-left: 2px;
            height: 30px;
            width: 30px
        }

        #firstImg {
            margin-left: 5px;
        }

        #lastInput {
            margin-left: 16px;
        }
    </style>
</head>
<body>
<div id="toolbar" class="panel panel-primary">
    <div class='panel-heading'>
        <h5 class='panel-title text-center' data-i18n="resources.text_cartoCSSPoint">点符号</h5></div>
    <div class='panel-body content'>
          <div class='input-group'>
              <label id="text" data-i18n="resources.text_choosePointType">选择点类型：</label>
              <img id="firstImg" src="./images/marker_red.png">
              <img src="./images/marker_black.png">
              <img src="./images/marker_blue.png"> <br/>
          </div>
          <div class='input-group' style="padding-left: 99px;">
              <input type="radio" class="btn" name="image" value="marker_red" onclick="selectPoint(this.value)"/>
              <input type="radio" class="btn" name="image" value="marker_black" onclick="selectPoint(this.value)"
                     style="margin-left: 18px"/>
              <input id="lastInput" type="radio" class="btn" name="image" value="marker_blue"
                     onclick="selectPoint(this.value)" style="margin-left: 18px"/>
          </div>
    </div>
</div>
<div id="map"></div>
<script type="text/javascript" include="bootstrap,widgets.alert" src="../js/include-web.js"></script>
<script type="text/javascript" exclude="iclient-classic" src="../../dist/classic/include-classic.js"></script>
<script type="text" id="textData">
        #World_Continent_pl___China{
        polygon-fill:#666;
        }
        #China_ProCenCity_pt___China{
        point-file:<%=pointFile>;
        point-offset-y:<%=offsetY>;
        }
</script>
<script>
    var map, layer, cartoCss,
        host = window.isLocal ? window.server : "https://iserver.supermap.io",
        url = host + "/iserver/services/map-china400/rest/maps/China";
    init();

    function init() {
        if (!document.createElement('canvas').getContext) {
            widgets.alert.showAlert(resources.msg_supportCanvas, false);
            return;
        }

        map = new SuperMap.Map("map", {
            controls: [
                new SuperMap.Control.ScaleLine(),
                new SuperMap.Control.Zoom(),
                new SuperMap.Control.MousePosition(),
                new SuperMap.Control.Navigation({
                    dragPanOptions: {
                        enableKinetic: true
                    }
                })]
        });
        cartoCss = document.getElementById("textData").text;
        var valueMap = {pointFile: "", offsetY: 0};
        var cartoCssStr = replaceString(cartoCss, valueMap);
        layer = new SuperMap.Layer.TiledVectorLayer("China", url, {
            cacheEnabled: true,
            returnAttributes: true
        }, {useLocalStorage: true, cartoCss: cartoCssStr, donotNeedServerCartoCss: true});
        layer.events.on({"layerInitialized": addLayer});
    }


    function addLayer() {
        map.addLayers([layer]);
        var center = new SuperMap.LonLat(11793760, 4407704);
        map.setCenter(center, 6);
    }

    function replaceString(str, obj) {
        for (var prop in obj) {
            var regexp = new RegExp("<%=" + prop + ">", "gi");
            str = str.replace(regexp, obj[prop]);
        }
        return str;
    }

    function selectPoint(imgName) {
        var imgUrl = "url(./images/" + imgName + ".png)";
        var valueMap = {pointFile: imgUrl, offsetY: -8};
        var cartocssStr = replaceString(cartoCss, valueMap);
        layer.setCartoCSS(cartocssStr);
    }

</script>

</body>
</html>